package core.testes.semantic;

import java.io.File;
import java.io.FileReader;

import core.codeGeneration.CodeGenerator;
import core.error.ErrorHandler;
import core.lexical.LexicalAnalyser;
import core.semantic.SemanticException;
import core.syntatic.SyntaticAnalyser;
import junit.framework.TestCase;

/**
 * It tests the relational expressions semantic.
 * @author Administrador
 *
 */
public class RelationalExpressionTest extends TestCase{
	
	private SyntaticAnalyser parser;

	@Override
	protected void setUp() throws Exception {
		String fileName = "examples\\relationalExpressionTest.ford";
		
		FileReader source = new FileReader( new File( fileName ) );
		
		 parser = new SyntaticAnalyser(	new LexicalAnalyser( source, new ErrorHandler() ) );
		 CodeGenerator.getInstace().init(fileName.substring(9, fileName.length() - 5));
	}

	public void testTypeMismatched() {
		try {
			parser.analyseIt();
			fail("Exception expected.");
		} catch (SemanticException e) {
			assertEquals(e.getErrors().get( 0 ), "line 8: The relational operations are undifined for the argument type(s) string, int");
		}
	}
}
